package main

import (
	"github.com/julienschmidt/httprouter"
	log "github.com/sirupsen/logrus"
	"go_study/vidioWeb/common"
	"go_study/vidioWeb/dbops"
	"go_study/vidioWeb/handler"
	"net/http"
	"reflect"
)

func main() {
	test()
	dbops.Test()

	router := &common.DefinedRouter{httprouter.New()}

	router.GlobalOPTIONS = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
	})

	handler.SetDefaultDual(router)

	router.GET("/test", handler.UserAdd)
	router.POST("/testPost", handler.VideoAdd)

	serve := http.ListenAndServe(":8888", router)
	log.Error("启动错误：%s", serve)
}

func test() {
	typeOf := reflect.ValueOf(&common.DefinedRouter{})
	log.Info(typeOf.Type().Name())
	log.Info(typeOf.Kind().String())

	for i := 0; i < typeOf.NumMethod(); i++ {
		log.Info("----------")
		log.Info(typeOf.Type().Method(i).Name)
		log.Info(typeOf.Type().Method(i).Type.String())
		log.Info(typeOf.Type().Method(i).PkgPath)
		log.Info(typeOf.Method(i).Type().Name())
		log.Info(typeOf.Method(i).Type().Kind().String())
		log.Info("----------")
	}

	method, _ := reflect.TypeOf(&common.DefinedRouter{}).MethodByName("ServeHTTP")

	log.Info(method.Name)
	//method.Call(nil)
}
